const MyPromise = require('./MyPromise')

const promise = new MyPromise((resolve, reject) => {
  resolve('success')
  // resolve('rejected')
  // resolve('timeout success')
})
const p1 = new MyPromise((resolve, reject) => {
  resolve('p1 resolve')
  // reject('p1 reject')
})
const p2 = new MyPromise((resolve, reject) => {
  setTimeout(() => {
    resolve('p2 resolve')
  }, 2000)
  // reject('p1 reject')
})
// const p2 = promise.then(value => {
//   console.log(1, value)
//   return p2
// });

// p2.then(value => {
//   console.log(2, value)
// }, reason => {
//   console.log(999, reason)
// })
// new MyPromise((resolve, reject) => {
//   // resolve('success')
//   reject('reject')
// }).then(value => {
//   console.log(1, value)
//   return 100
// }, reason => {
//   console.log(1, reason)
//   throw new Error('123')
// }).then(value => {
//   console.log(2, value)
// }, reason => {
//   console.log('2 reject', reason)
// })

// new MyPromise((resolve, reject) => {
//   setTimeout(() => {
//     resolve(111)
//   }, 1000)
// }).then(value => {
//   console.log('1resolve', value)
//   return 200
// }).then(value => {
//   console.log('2resolve', value)
// }, reason => {
//   console.log(1234, reason)
// })

// MyPromise.all(['a', 'b', p1, p2]).then(result => {
//   console.log(result)
// }, reason => {
//   console.log(reason)
// })

// MyPromise.resolve('1234').then(value => console.log(value))
// MyPromise.resolve(p1).then(value => console.log(value))
// new MyPromise((resolve, reject) => {
//   reject('12312')
// }).finally(() => {
//   console.log('finally')
//   return p2
// }).then(value => {
//   console.log('999', value)
// }, reason => {
//   console.log('reject', reason)
// })

new MyPromise((resolve, reject) => {
  reject('12312')
}).then(value => {
  console.log('111 resolve', value)
}, reason => {
  console.log('111 reject', reason)
  return '123'
}).then(value => {
  console.log('222 resolve', value)
})